package com.example.waterdispenserm2.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.waterdispenserm2.R;
import com.example.waterdispenserm2.bean.LanguageBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 错误信息列表适配器
 */
public class LanguageAdapter extends BaseAdapter {
    private final Context context;
    private List<LanguageBean> languageList;
    private int type=-1;

    public void setType(int type) {
        this.type = type;
    }

    public LanguageAdapter(Context context, List<LanguageBean> languageList) {
        this.context = context;
        this.languageList = languageList;
    }

    @Override
    public int getCount() {
        return languageList.size();
    }

    @Override
    public Object getItem(int position) {
        return languageList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.language_item, parent, false);
        }
        
        TextView tvEn = convertView.findViewById(R.id.tv_en_item);
        ImageView iv_en = convertView.findViewById(R.id.iv_en_item);

        tvEn.setText(languageList.get(position).getRealName());


        if (type==position){
            iv_en.setVisibility(View.VISIBLE);
        }else {
            iv_en.setVisibility(View.GONE);
        }
        
        return convertView;
    }

}